<?php

namespace app\admin\model\system;

use think\Model;


class Filemanage extends Model
{

    
    

    // 表名
    protected $name = 'file_manage';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    protected $dateFormat = 'Y-m-d H:i:s';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text'
    ];
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }

    
    /**
     * 更新附件配置
     */
    public static function updateAttachmentConfig()
    {
        $route = self::where('status', 1)->column('category', 'name');
        $route = json_encode($route, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        $value = \app\common\model\Config::where('name', 'attachmentcategory')->update(['value' => $route]);
        // 刷新配置
        \app\common\model\Config::refreshFile();
        return $route;
    }
}
